{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.随机数生成六个班的考试成绩，3门考试：Python、数学、语文。每个班50人"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "arr = np.random.randint(0,101,(6,50,3))\n",
    "arr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.将六个班的考试成绩进行合并得到score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "score = np.sum(arr,axis=0)\n",
    "score"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.生成性别数组sex，水平叠加数组sex和score得到data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sex = np.random.randint(0,2,(50,1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = np.hstack((sex,score))\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.分别计算男女生各科成绩统计指标：最小值、最大值、平均分、中位数、标准差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#男生(data[:,0] == 1)各科成绩最小值\n",
    "np.where(data[:,0]==1,data[:,1:4].min(axis=1),0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#男生(data[:,0] == 1)各科成绩最大值\n",
    "np.where(data[:,0]==1,data[:,1:4].max(axis=1),0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#男生(data[:,0] == 1)各科成绩平均分\n",
    "np.where(data[:,0]==1,data[:,1:4].mean(axis=1),0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#男生(data[:,0] == 1)各科成绩中位数\n",
    "np.where(data[:,0]==1,np.median(data[:,1:4],axis=1),0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#男生(data[:,0] == 1)各科成绩标准差\n",
    "np.where(data[:,0]==1,data[:,1:4].std(axis=1),0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#女生(data[:,0] == 0)各科成绩最小值\n",
    "np.where(data[:,0]==0,data[:,1:4].min(axis=1),0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#女生(data[:,0] == 0)各科成绩最大值\n",
    "np.where(data[:,0]==0,data[:,1:4].max(axis=1),0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#女生(data[:,0] == 0)各科成绩平均分\n",
    "np.where(data[:,0]==0,data[:,1:4].mean(axis=1),0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#女生(data[:,0] == 0)各科成绩中位数\n",
    "np.where(data[:,0]==0,np.median(data[:,1:4],axis=1),0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#女生(data[:,0] == 0)各科成绩标准差\n",
    "np.where(data[:,0]==0,data[:,1:4].std(axis=1),0)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
